-[ sponsor this site! ]-

CGI Library

CGI Library

Enough people have asked me about CGI's, how to do them, etc., that I thought I'd start a little page with links to some of the more common/usual stuff. I hope you find it helpful.

This page is now part of the Web Engineer's Toolbox.. Visit the toolbox for more useful web goodies and information.

All my CGI's are written in Perl on Unix. For more info about Perl, please visit our Perl Archive here on Metronet, which is maintained by Bill Middleton (wjm@metronet.com).

Also, while it isn't available as a generic CGI, I've written a 256 color square you can use to find the RGB value of a given color. It's useful for picking out background, text, and link colors for documents.


NOTE: Here are a few tips to help get your cgi's working on your server. First, be sure that your server supports cgi execution. If not, you'll have to put the cgi in the system's cgi-bin. Second, be sure you chmod 755 scriptname.cgi so that it is executable. And finally, if you download these scripts to a PC, then re-upload them to another unix server, be sure to upload them as ASCII rather than binary.

Mailto CGI's: The first CGI that most folks want to do is one that emails them the output from some form. There is a good general purpose one on the above archive, and in fact it is the same form-mail.pl that I have taken and modified a hundred times or more for this sort of thing.


Imagemaps are a fairly common phenomenon on the Web. An imagemaps is just a gif image that is "clickable" - that is, you click on a certain part of the image, and it sends you off to a new page. I've written an imagemap tutorial that describes how to set one up. Admittedly this tutorial is written for people using Metronet to host their pages, but it does still give a pretty good general idea for anyone wanting to set up an imagemap.


Counters are popular, although there's some dissention among HTML designers as to whether a graphical counter on a page is a good idea. If you have low hit counts, it can be a negative thing, only emphasizing just how few hits you're getting. High counts make counters nice, but still a debatable design element. But enough philosophizing, here's some code:


Inline Animation, or the Netscape push-pull hack, is not that difficult. The hardest part is usually finding a script to do the actual animation. Here's a simple perl script that does it. I hacked this from a version of nph-animate, or something like that... I don't remember now. You have to edit it to replace the various gif filenames that will be the different "frames" of your animation, but that's it.

Server-push animation is almost uncool now; it's more popular and common (and considerably easier) to simply create an animated gif for this, though many people find animated gifs annoying as they constantly reload images from the disk cache.


Redirection Scripts may be necessary if you have a page that supports certain Netscape-specific features, and want to only show that page to visitors who are actually using Netscape. This example is the one I use for my homepage; in lieu of any index.html file, the server hits this script (named index.cgi) and redirects the incoming request to the proper html file.


Finger Script - this can be modified to perform basically any unix command, and print the output to a web page.


That's about all I have for now, though I welcome suggestions for additions to my cookbook of generic CGI's. Certainly there's lots of need for specialized CGI's depending on your application, and if you're wanting to learn how to write CGI's, I'll suggest these books:

There are also (at least) two newsgroups I would recommend:


Interested in learning perl online? Visit the Online Perl Class part of this site.


Kira's Home | Toolbox